package com.justgame.project.service.api.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.justgame.project.cloud.common.util.HttpContextUtil;
import com.justgame.project.cloud.common.util.ShiroUtils;
import com.justgame.project.cloud.common.util.IdUtils;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;

import java.io.Serializable;
import java.util.Date;

/**
 * 查看详情记录表
 */
@Data
public class ViewGame implements Serializable {
    private final static long serialVersionUID = 1L;

    private String id;
    private String gameId;
    private String sysUserId;
    private String ip;

    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date time;


    public ViewGame() {
    }

    public ViewGame(String id, String gameId, String sysUserId, Date time, String ip) {
        this.id = id;
        this.gameId = gameId;
        this.sysUserId = sysUserId;
        this.ip = ip;
        this.time = time;
    }

    /**
     * 快捷构造器
     */
    public ViewGame(String gameId) {
        this.id = IdUtils.create();
        this.gameId = gameId;
        try {
            this.sysUserId = ShiroUtils.getUserId();
        } catch (Exception e) {
            this.sysUserId = null;
        }
        try {
            this.ip = HttpContextUtil.getIp();
        } catch (Exception e) {
            this.ip = null;
        }
        this.time = new Date();
    }

}
